var BearSprite =cc.Sprite.extend({
	velocity:null,
	radius:25,//碰撞半径
	ctor:function(){
		this._super();
		this.initWithFile(s_bear_eyesopen);
		this.velocity=cc.p(150,150);
	},

	beginRotate:function(){
		var rotate=cc.RotateBy.create(2,360);
		var repl=cc.RepeatForever.create(rotate);
		this.runAction(repl);
	},
	stopRotate:function(){
		this.stopAllAction();
	},

	update:function(dt){
		this.setPosition(cc.pAdd(this.getPosition(),cc.pMult(this.velocity,dt)));
		this.checkHitEdge();
	},

	//检查边界碰撞
	checkHitEdge:function(){
		var pos=this.getPosition();
		var winSize=cc.Director.getInstance().getWinSize();
		//right
		if(pos.x>winSize.width-this.radius){
			this.velocity.x*=-1;
		}
		//left
		if(pos.x<this.radius){
			this.velocity.x*=-1;
		}
		//down
		if(pos.y<=this.radius){
			this.curSence.reduceLives();
		}
		if(pos.y>=winSize.height-this.radius){
			this.velocity.y*=-1;
		}
	},

	//碰撞检测
	collide:function(gameObject){
		var hit=false;
		var distance=cc.pDistance(this.getPosition(),gameObject.getPosition());
		if(distance<=this.radius+gameObject.radius){
			hit=true;
			var hitAngle=cc.pToAngle(cc.pSub(gameObject.getPosition(),this.getPosition()));
			var scalarVelocity=cc.pLength(this.velocity);
			this.velocity=cc.pMult(cc.pForAngle(hitAngle),scalarVelocity);
			this.velocity.x*=-1;
			this.velocity.y*=-1;
		}
		return hit;
	}
});
